#ifndef __H_SHADOW_CALC__
#define __H_SHADOW_CALC__

#include "const_define.fx"

texture TEX_SHADOW_MAP = NULL;
sampler SamplerShadowMap = sampler_state
{
	Texture = <TEX_SHADOW_MAP>;
	MinFilter = Point;
	MagFilter = Point;
	MipFilter = Point;
	AddressU = Border;
	AddressV = Border;
	BorderColor = 0xffffffff;
};

float4 CalcShadowProjTexCoord(float3 position)
{
	float4 lightPos = mul(float4(position, 1.0f), MAT_LIGHT_WORLD_VIEW_PROJ);
	float z = lightPos.z;
	float w = lightPos.w;
	lightPos = mul(lightPos, MAT_SHADOW_MAP_WRAP);
	float x = 0.5f + lightPos.x * 0.5f;
	float y = 0.5f - lightPos.y * 0.5f;
	return float4(x, y, z, w);
}

float CalcShadow(float4 texProj)
{
	float depthCheck = texProj.z / texProj.w;
	float shadowDepth = tex2D(SamplerShadowMap, texProj.xy).r;
	return depthCheck > shadowDepth + 0.001f ? 0.3f : 1.0f;
}

#endif // __H_SHADOW_CALC__